package demo.intercepter;


import demo.db.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginIntercepter extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        User user = new User();
        if (username.equals("a") && password.equals("b")) {
            user.setUsername("a");
            user.setPassword("a");
        }
        request.setAttribute("user", user);
        return true;
    }
}
